package main

import "fmt"

func maxArea(height []int) int {
	left, right := 0, len(height)-1
	res := 0
	for left < right {
		if h := (right - left) * min(height[left], height[right]); h > res {
			res = h
		}
		if height[left] < height[right] {
			left++
		} else {
			right--
		}
	}
	return res
}

func main() {
	height := []int{1, 8, 6, 2, 5, 4, 8, 3, 7}
	res := maxArea(height)
	fmt.Println(res)
}
